package com.cswangdao.service.impl;

import com.cswangdao.domain.dto.CommentPageDTO;
import com.cswangdao.domain.model.MarketComment;
import com.cswangdao.mapper.MarketCommentMapper;
import com.cswangdao.result.PageResult;
import com.cswangdao.service.CommentService;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CommentServiceImpl implements CommentService {
    @Autowired
    private MarketCommentMapper commentMapper;

    @Override
    public PageResult<MarketComment> pageQueryInfo(CommentPageDTO pageDTO) {
        try/*(SqlSession sqlSession = MybatisUtil.getSqlSession())*/ {
         //   MarketCommentMapper commentMapper = sqlSession.getMapper(MarketCommentMapper.class);
            PageHelper.startPage(pageDTO.getPage(), pageDTO.getLimit());
            Page<MarketComment> commentPage = commentMapper.pageQueryInfo(pageDTO);
            PageResult<MarketComment> result = PageResult.result(commentPage);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public void deleteById(Integer id) {
        try/*( SqlSession sqlSession = MybatisUtil.getSqlSession();) */{
         //   MarketCommentMapper commentMapper = sqlSession.getMapper(MarketCommentMapper.class);
            commentMapper.deleteById(id);
        //    sqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
